package com.wangxin.study8.lock;

import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName RedisService
 * @Description TODO
 * @Author jojo.wang
 * @Date 2019-05-29 20:14
 * @Version 1.0
 **/
@Service
public class RedisService {
    /**
     * 原子操作释放锁 Lua 脚本
     */
    private static final String LUA_UNLOCK_SCRIPT = "if redis.call(\"get\", KEYS[1]) == ARGV[1] " +
            "then " +
            "return redis.call(\"del\", KEYS[1]) " +
            "else " +
            "return 0 " +
            "end";

    public String set(String key ,String token,String nx,String ex ,long expire){
        return "OK";
    }

    public String get(String key){
        return "OK";
    }

    public boolean del(List<String> keys, List<String> args){
        // TODO: 2019-05-29 此处可以使用lua脚本执行删除操作
        // return ((JedisCluster) nativeConnection).eval(LUA_UNLOCK_SCRIPT, keys, args);
        System.out.println("del");
        // 判断执行结果是否是null并且长度是否大于0

        return true;
    }
}
